package task;

class Singleton{
    private static Object lock = new Object();
    private static volatile Singleton instance = null;
    public static Singleton getInstance(){
        if(instance == null){
            synchronized (lock){
                if(instance == null){
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

    private Singleton(){};
}

public class Test6 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            Singleton singleton1 = Singleton.getInstance();
        });
        Thread t2 = new Thread(() -> {
            Singleton singleton2 = Singleton.getInstance();
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
